#include <stdio.h>

void swap(int u, int v)
{
	int temp;
	
	printf("u = %d v = %d\n", u, v);
	temp = u;
	u = v;
	v = temp;
	printf("u = %d v = %d\n", u, v);
}

void errswap(int *a, int *b)
{
	int *temp;

	temp = NULL;
	temp = a;
	a = b;
	b = temp;
}

void pswap(int *u, int *v)
{
	int temp;
	
	//printf("u = %d v = %d\n", &u, &v);
	temp = *u;
	*u = *v;
	*v = temp;
	//printf("u = %d v = %d\n", &u, &v);
}

void ppswap(int **a, int **b)
{
	int *tmp = NULL;

	tmp = *a;
	*a = *b;
	*b = tmp;
}

#define SWAP(a, b, size)						      \
  do									      \
    {									      \
      register size_t __size = (size);					      \
      register char *__a = (a), *__b = (b);				      \
      do								      \
	{								      \
	  char __tmp = *__a;						      \
	  printf("a = %d b = %d\n", (a), (b));	\
	  *__a++ = *__b;						      \
	  *__b++ = __tmp;						      \
	  printf("a = %d b = %d\n", (a), (b));	\
	} while (--__size > 0);						      \
    } while (0)

int main()
{
	int a = 3, b = 4;
	int *pa = &a, *pb = &b;

	swap(a, b);
	printf("swap : a = %d b = %d\n", a, b);	// 3	4

	errswap(&a, &b);
	printf("errswap : a = %d b = %d\n", a, b);	// 3	4
	
	pswap(&a, &b);
	printf("a = %d b = %d\n", a, b);	// 4	3

	ppswap(&pa, &pb);
	printf("a = %d b = %d\n", a, b);	// 4	3

	SWAP(pa,pb,3);
	
	return 0;
}

